home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gxmclip.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  3.5 KB  |  106 lines

  1. /* Copyright (C) 1998, 1999 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gxmclip.c,v 1.2 2000/09/19 19:00:39 lpd Exp $ */
  20. /* Mask clipping support */
  21. #include "gx.h"
  22. #include "gxdevice.h"
  23. #include "gxdevmem.h"
  24. #include "gxmclip.h"
  25.  
  26. /* Structure descriptor */
  27. public_st_device_mask_clip();
  28.  
  29. /* GC procedures */
  30. private ENUM_PTRS_WITH(device_mask_clip_enum_ptrs, gx_device_mask_clip *mcdev)
  31. {
  32.     if (index < st_gx_strip_bitmap_max_ptrs) {
  33.     return ENUM_USING(st_gx_strip_bitmap, &mcdev->tiles,
  34.               sizeof(mcdev->tiles), index);
  35.     }
  36.     index -= st_gx_strip_bitmap_max_ptrs;
  37.     if (index < st_device_memory_max_ptrs) {
  38.     return ENUM_USING(st_device_memory, &mcdev->mdev,
  39.               sizeof(mcdev->mdev), index);
  40.     }
  41.     ENUM_PREFIX(st_device_forward, st_device_memory_max_ptrs);
  42. }
  43. ENUM_PTRS_END
  44. private RELOC_PTRS_WITH(device_mask_clip_reloc_ptrs, gx_device_mask_clip *mcdev)
  45. {
  46.     RELOC_PREFIX(st_device_forward);
  47.     RELOC_USING(st_gx_strip_bitmap, &mcdev->tiles, sizeof(mcdev->tiles));
  48.     RELOC_USING(st_device_memory, &mcdev->mdev, sizeof(mcdev->mdev));
  49.     if (mcdev->mdev.base != 0) {
  50.     /*
  51.      * Update the line pointers specially, since they point into the
  52.      * buffer that is part of the mask clipping device itself.
  53.      */
  54.     long diff = (char *)RELOC_OBJ(mcdev) - (char *)mcdev;
  55.     int i;
  56.  
  57.     for (i = 0; i < mcdev->mdev.height; ++i)
  58.         mcdev->mdev.line_ptrs[i] += diff;
  59.     mcdev->mdev.base = mcdev->mdev.line_ptrs[0];
  60.     mcdev->mdev.line_ptrs =
  61.         (void *)((char *)(mcdev->mdev.line_ptrs) + diff);
  62.     }
  63. }
  64. RELOC_PTRS_END
  65.  
  66. /* Initialize a mask clipping device. */
  67. int
  68. gx_mask_clip_initialize(gx_device_mask_clip * cdev,
  69.             const gx_device_mask_clip * proto,
  70.             const gx_bitmap * bits, gx_device * tdev,
  71.             int tx, int ty, gs_memory_t *mem)
  72. {
  73.     int buffer_width = bits->size.x;
  74.     int buffer_height =
  75.     tile_clip_buffer_size / (bits->raster + sizeof(byte *));
  76.  
  77.     gx_device_init((gx_device *)cdev, (const gx_device *)proto,
  78.            mem, true);
  79.     cdev->width = tdev->width;
  80.     cdev->height = tdev->height;
  81.     cdev->color_info = tdev->color_info;
  82.     gx_device_set_target((gx_device_forward *)cdev, tdev);
  83.     cdev->phase.x = -tx;
  84.     cdev->phase.y = -ty;
  85.     if (buffer_height > bits->size.y)
  86.     buffer_height = bits->size.y;
  87.     gs_make_mem_mono_device(&cdev->mdev, 0, 0);
  88.     for (;;) {
  89.     if (buffer_height <= 0) {
  90.         /*
  91.          * The tile is too wide to buffer even one scan line.
  92.          * We could do copy_mono in chunks, but for now, we punt.
  93.          */
  94.         cdev->mdev.base = 0;
  95.         return 0;
  96.     }
  97.     cdev->mdev.width = buffer_width;
  98.     cdev->mdev.height = buffer_height;
  99.     if (gdev_mem_bitmap_size(&cdev->mdev) <= tile_clip_buffer_size)
  100.         break;
  101.     buffer_height--;
  102.     }
  103.     cdev->mdev.base = cdev->buffer.bytes;
  104.     return (*dev_proc(&cdev->mdev, open_device))((gx_device *)&cdev->mdev);
  105. }
  106.